<template>
	<view class="container">
		<view class="sign-in-header-box"> </view>
		<view style="padding: 20rpx 40rpx">
			<view class="content-box">
				<ren-calendar ref="ren" :collapsible='false' :markDays="markDays" :headerBar="false"
					@onDayClick="onDayClick" :disabledAfter='true'></ren-calendar>
				<view>
					<view><u-button type="primary" text="签到" color="#ffaa00" @click="signInClick"></u-button></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		checkIn,
		monthCheckInInfo
	} from "@/api/axios/Space.js";
	import store from "@/store/index.js";
	import RenCalendar from "./ren-calendar/ren-calendar.vue";
	export default {
		components: {
			RenCalendar
		},
		data() {
			return {
				openId: "openId",
				current: 0,
				curDate: "",
				markDays: [],
			};
		},
		methods: {
			onDayClick(data) {

				// this.curDate = data.date;
			},
			signInClick() {
				let _this = this;
				let mapData = store.state.mapData;
				if (mapData.address) {
					checkIn({
						openId: this.openId,
						location: mapData.address,
						longitude: mapData.location.lng,
						latitude: mapData.location.lat,
					}).then((res) => {
						_this.clue({
							action: "12",
							eventType: "1",
						});
						uni.showToast({
							icon: "none",
							title: '打卡签到成功',
							duration: 2000,
						});
						// setTimeout(() => {
						// 	uni.navigateBack({
						// 		delta: 1,
						// 	});
						// }, 2000)

					});
				} else {
					checkIn({
						openId: this.openId,
						// location: mapData.address,
						// longitude: mapData.location.lng,
						// latitude: mapData.location.lat,
					}).then((res) => {
						console.log(res);
						uni.showToast({
							icon: "none",
							title: '打卡签到成功',
							duration: 2000,

						});
						// setTimeout(() => {
						// 	uni.navigateBack({
						// 		delta: 1,
						// 	});
						// }, 2000)
					});
				}
			},
		},
		onLoad() {
			let today = this.$refs.ren.getToday().date;
			this.curDate = today;
			// this.markDays.push(today);
			let openId = uni.getStorageSync("openId");
			this.openId = openId;
			let date = new Date()
			let getFullYear = date.getFullYear()
			let getMonth = date.getMonth()
			monthCheckInInfo({
				params: {
					openId: openId,
					date: getFullYear + '-' + (getMonth + 1)
				}
			}).then(res => {
				let arr = res.map(item => {
					return item.checkInTime.split(' ')[0]
				})
				console.log(this.markDays);
				this.markDays = arr
			})
		},
	};
</script>

<style lang="scss" scoped>
	@import "./index.scss";
</style>